using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.Windows;
using System.Windows.Input;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows.Documents;

namespace WozLib.UI.Ink.SketchCommands
{
  public class HideHourglassSketchCommand : SketchCommand
  {

    public HideHourglassSketchCommand()
      : base()
    {
    }

    public override void Redo()
    {
      if (this.WozClientCommandReferences != null && this.WozClientCommandReferences.InkCanvas != null)
      {
        // this is commented out sample code in case we want to keep
        // a single reference to an hourglass object later

        //lock (this.WozClientCommandReferences.InkOverlayCanvas)
        //{
        //  if (this.WozClientCommandReferences.InkOverlayEllipse == null)
        //  {
        //    this.WozClientCommandReferences.InkOverlayEllipse = new Ellipse();

        //    // just want a local ref for intellisense to work
        //    Ellipse ellipse = this.WozClientCommandReferences.InkOverlayEllipse;

        //    ellipse.Width = 5;
        //    ellipse.Height = 5;
        //    ellipse.Fill = Brushes.Red;
        //    ellipse.Visibility = Visibility.Hidden;
        //    this.WozClientCommandReferences.InkOverlayCanvas.Children.Add(ellipse);
        //  }
        //}

        //this.WozClientCommandReferences.InkCanvas.Background = Brushes.DarkMagenta;
        this.WozClientCommandReferences.InkCanvas.UseCustomCursor = false;
        this.WozClientCommandReferences.InkCanvas.UpdateUserCurrentInkTool();

        if (this.WozClientCommandReferences.InkCanvas != null && 
          this.WozClientCommandReferences.InkCanvas.UIElementToAdorn != null &&
          this.WozClientCommandReferences.InkCanvas.HourglassAdorner != null)
        {
          this.WozClientCommandReferences.InkCanvas.HourglassAdorner.Visibility = Visibility.Hidden;

          AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(
              this.WozClientCommandReferences.InkCanvas.UIElementToAdorn);

          if (adornerLayer.GetAdorners(this.WozClientCommandReferences.InkCanvas.UIElementToAdorn) != null)
          {
            adornerLayer.Update(this.WozClientCommandReferences.InkCanvas.UIElementToAdorn);
          }
        }
      }
    }

    public override void Undo()
    {
      // not really anything to undo for this command
      // I mean we could take the hour glass away
      // but we assume a clear is going to happen later anyway
      // and the input mode is going to change too
    }
  }
}

